﻿using System;
using System.Globalization;
using System.Windows.Data;
using System.Windows.Media.Imaging;

namespace MT.CustomUserControl.Convert
{
    [ValueConversion(typeof(string), typeof(BitmapImage))]
    public class ImageByStringConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            string temp = (string)value;
            if (!string.IsNullOrEmpty(temp))
            {
                temp = temp.Remove(0, temp.Length - 3);
                if (temp == "pdf")
                {
                    return new BitmapImage(new Uri("pack://application:,,,/MT.CustomUserControl;component/Images/pdf.png", UriKind.RelativeOrAbsolute));
                }
                else
                {
                    return new BitmapImage(new Uri("pack://application:,,,/MT.CustomUserControl;component/Images/doc.png", UriKind.RelativeOrAbsolute));
                }
            }
            else
            {
                return null;
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw null;
        }
    }
}
